<%-- 
    Document   : employeemaster_db
    Created on : Jan 10, 2013, 7:18:51 PM
    Author     : kk
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*, java.io.*, org.json.simple.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
         String empid=new String("a1");
         String photopath=new String("abcd");
        try{
            String firstname=request.getParameter("emp-first-name");
            String middlename=request.getParameter("emp-middle-name");
            String lastname=request.getParameter("emp-last-name");
            String mothername=request.getParameter("emp-mother-name");
            String cast=request.getParameter("emp-cast");
            String castcategory=request.getParameter("emp-cast-category");
            String birthdate=request.getParameter("emp-birth-date");
            String city=request.getParameter("emp-birth-city");
            String state=request.getParameter("emp-birth-state");
            String country=request.getParameter("emp-birth-country");
            String bloodgroup=request.getParameter("emp-bloodgroup");
            String presentaddress=request.getParameter("emp-present-address");
            String permanentaddress=request.getParameter("emp-permanent-address");
            String permanentcity=request.getParameter("emp-permanent-city");
            String permanentstate=request.getParameter("emp-permanent-state");
            String permanentcountry=request.getParameter("emp-permanent-country");
            String permanentpincode=request.getParameter("emp-permanent-pincode");
            String nationality=request.getParameter("emp-nationality");
            String religion=request.getParameter("emp-religion");
            String employeecontactno=request.getParameter("emp-contact-no");
            String alternativecontactno=request.getParameter("emp-alter-no");
            String joiningdate=request.getParameter("emp-joining-date");
            String totalsubjects=request.getParameter("emp-total-subjects");
            String standard=request.getParameter("emp-standard");
            String subject=request.getParameter("emp-subject");
            String qualificationdegree=request.getParameter("emp-qualification-degree");
            String qualificationper=request.getParameter("emp-qualification-per");
            String qualificationscu=request.getParameter("emp-qualification-scu");
            String qualificationyear=request.getParameter("emp-qualification-year");
            String experienceinst=request.getParameter("emp-experience-inst");
            String experienceduration=request.getParameter("emp-experience-duration");
            String experiencejobdesc=request.getParameter("emp-experience-jobdesc");
            String remark=request.getParameter("emp-remark");
            
            JSONObject obj=new JSONObject();
            
            obj.put("firstname", firstname);
            obj.put("middlename", middlename);
            obj.put("lastname", lastname);
            obj.put("mothername", mothername);
            obj.put("cast", cast);
            obj.put("castcategory", castcategory);
            obj.put("birthdate", birthdate);
            
            
            JSONObject birthplace=new JSONObject();
                birthplace.put("city", city);
                birthplace.put("state", state);
                birthplace.put("country", country);
            obj.put("birthplace", birthplace);
            
            obj.put("bloodgroup", bloodgroup);
            
            JSONObject address=new JSONObject();
                address.put("presentaddress", presentaddress);
                    JSONObject permanent=new JSONObject();
                        permanent.put("permanentaddress", permanentaddress);
                        permanent.put("city", permanentcity);
                        permanent.put("state", permanentstate);
                        permanent.put("country", permanentcountry);
                        permanent.put("pincode", permanentpincode);
                address.put("permanentaddress", permanent);
            obj.put("address", address);
            
            obj.put("nationality", nationality);
            obj.put("religion", religion);
            
            JSONObject contactno=new JSONObject();
                contactno.put("employee", employeecontactno);
                contactno.put("alternative", alternativecontactno);
            obj.put("contactno", contactno);
            
            obj.put("joiningdate", joiningdate);
            obj.put("totalsubjects", totalsubjects);
            obj.put("standard", standard);
            obj.put("subject", subject);
            
            JSONObject qualification=new JSONObject();
                qualification.put("qualificationdegree", qualificationdegree);
                qualification.put("qualificationper", qualificationper);
                qualification.put("qualificationscu", qualificationscu);
                qualification.put("qualificationyear", qualificationyear);
            obj.put("qualification", qualification);
            
            JSONObject experience=new JSONObject();
                experience.put("experienceinst", experienceinst);
                experience.put("experienceduration", experienceduration);
                experience.put("experiencejobdesc", experiencejobdesc);
            obj.put("experience", experience);
            
            obj.put("remark", remark);
            
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shms", "root", "");
            String query="insert into employee_master (employee_id, employee_detail, photo) values ('"+empid+"','"+obj.toJSONString()+"','"+photopath+"') ";
            Statement stmt=con.createStatement();
            int rst=stmt.executeUpdate(query);
            
            if(rst == 1)
            {
            application.setAttribute("msg","true");
            }
            else
            {
            application.setAttribute("msg","false");
            }
            
            response.sendRedirect("employeemaster.jsp");
               
        }
        catch(Exception e) {}
        %>
    </body>
</html>
